package com.examples.menu;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.Shell;

public class SubMenuItem {
	
	public static void main(String[] args) {

		final Display d = Display.getDefault();
	    Shell s = new Shell(d);
	    s.setLayout(new FillLayout());
	    s.setText("Sub Menu Example");
	    
	    Menu m = new Menu(s, SWT.BAR);
	    
	    MenuItem file = new MenuItem(m, SWT.CASCADE);
	    file.setText("File");
	    MenuItem edit = new MenuItem(m, SWT.CASCADE);
	    edit.setText("Edit");
	    
	    final Menu filemenu = new Menu(s, SWT.DROP_DOWN);
	    file.setMenu(filemenu);
	    MenuItem open = new MenuItem(filemenu, SWT.CASCADE);
	    open.setText("New                          Alt+Shift+N");
	    
	    Menu openMenu = new Menu(open);
	    open.setMenu(openMenu);
	    MenuItem submenu1 = new MenuItem(openMenu, SWT.CASCADE);
	    submenu1.setImage(d.getSystemImage(SWT.ICON_QUESTION));
	    submenu1.setText("Plugin Project");
	    MenuItem submenu2 = new MenuItem(openMenu, SWT.CASCADE);
	    submenu2.setImage(d.getSystemImage(SWT.ICON_INFORMATION));
	    submenu2.setText("Development Project");
	    
	    MenuItem exit = new MenuItem(filemenu, SWT.NONE);
	    exit.setText("Exit");
	    
	    exit.addSelectionListener(new SelectionListener() {
			
			@Override
			public void widgetSelected(SelectionEvent e) {
			d.dispose();	
			}
			
			@Override
			public void widgetDefaultSelected(SelectionEvent e) {
			}
		});
	   
	    s.setMenuBar(m);
	    
	    s.open();
	    while (!s.isDisposed()) {
	      if (!d.readAndDispatch())
	        d.sleep();
		}
	}
}